package com.qiyu.tech.task.future;

import java.util.concurrent.TimeUnit;

/**
 * @Author idea
 * @Date created in 12:27 下午 2020/11/30
 */
public class TestDemo {


    public static void main(String[] args) throws InterruptedException {
        FutureData<String> futureData = new FutureTask<String>(new TestJob());
//        for (int i=0;i<10;i++) {
//            System.out.println("this is "+i);
//            TimeUnit.SECONDS.sleep(1);
//        }
        String result = futureData.get();
        System.out.println("============ "+result+" ============");



    }

    public static class TestJob implements CallAbleTask<String>{

        public TestJob(){}

        @Override
        public String run() {
            try {
                Thread.sleep(1000);
                System.out.println("this is test job");
                return "success";
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "error";
        }
    }
}
